package com.laviedesfons.jhmtasc.types.internals;

import com.laviedesfons.jhmtasc.annotations.binding.MType;
import com.laviedesfons.jhmtasc.types.interfaces.InternalType;
import fr.x9c.cadmium.kernel.Block;
import fr.x9c.cadmium.kernel.Value;

/**
 *
 * @author Romano
 */
@MType(camlType="string")
public final class PString implements InternalType{

    protected String value;

    public PString(){}

    public PString(String v) {
        value = v;
    }

    public String asString(){
        return value;
    }

    @Override
    public PString fromValue(Value v) {
        value = v.asBlock().asString();
        return this;
    }

    @Override
    public Value toValue() {
        return Value.createFromBlock(Block.createString(value));
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PString other = (PString) obj;
        if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.value != null ? this.value.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return value;
    }
}
